import javax.xml.soap.Node;
import java.util.Stack;

public class BinaryTree {
    static class  NodeTree{
        int val;
        NodeTree left;
        NodeTree right;

        public NodeTree(int val) {
            this.val = val;
        }
    }
    public void createtree(){
        NodeTree node1 = new NodeTree(1);
        NodeTree node2 = new NodeTree(2);
        NodeTree node3 = new NodeTree(3);
        NodeTree node4 = new NodeTree(4);
        NodeTree node5 = new NodeTree(5);
        node1.left = node2;
    }

    public void inOrder(NodeTree root){
        if(root == null){
            return ;
        }
        NodeTree cur = root;
        Stack<NodeTree> stack = new Stack<>();
        while(cur != null || !stack.empty()){
            while(cur != null){
                stack.push(cur);
                System.out.println(cur.val +" ");
                cur = cur.left;
            }
            NodeTree top = stack.pop();
            cur = top.right;
        }
    }



    public void Onorder(NodeTree root){
        if(root == null){
            return;
        }
        NodeTree cur = root;
        Stack<NodeTree> stack = new Stack<>();
        while(cur !=  null || !stack.empty()){
            while(cur != null){
                stack.push(cur);
                cur = cur.left;
            }
            NodeTree top = stack.pop();
            System.out.println(top.val + " ");
            cur = top.right;
        }
    }
    public void postorder(NodeTree root) {
        if (root == null) {
            return;
        }
        NodeTree cur = root;
        Stack<NodeTree> stack = new Stack<>();
        while (cur != null || !stack.empty()) {
            while (cur != null) {
                stack.push(cur);
                cur = cur.left;
            }
            NodeTree top = stack.pop();
            NodeTree pre = null;
            if (top.right == null || top == pre) {
                System.out.println(top.val + " ");
                stack.pop();
            } else {
                cur = top.right;


            }
        }
    }
}
